package hdoj;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class HDU1010 {

	private static final char START = 'S';
	private static final char OBSTACLE = 'X';
	private static final char EXIT = 'D';
	
	public static final int[][] dir = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
	private static final int MAX = 10; 
	
	private int minMinute = Integer.MAX_VALUE;
	
	private int rows, columns, t; 
	
	private char[][] maze = new char[MAX][MAX];
	private boolean[][] visited = new boolean[MAX][MAX];
	
	//Java就是过不了啊
	public static void main(String[] args) {
		HDU1010 object = new HDU1010();
		object.getRes();
	}
	
	public void getRes(){
		Scanner scanner = new Scanner(System.in);
		int startX = 0, startY = 0;
		int endX = 0, endY = 0;
		
		while(scanner.hasNext()){
			minMinute = Integer.MAX_VALUE;
			rows = scanner.nextInt();
			columns = scanner.nextInt();
			t = scanner.nextInt();
			if(t == 0 && rows == 0 && columns == 0){
				break;
			}
			int blocks = 0;
			for (int j = 0; j < rows; j++) {
//				String string = scanner.next();
//				int index = string.indexOf(START);
//				if(startX == 0 && index != -1){
//					startX = j;
//					startY = index;
//				}
//				int indexEnd = string.indexOf(EXIT);
//				if(endX == 0 && indexEnd != -1){
//					endX = j;
//					endY = index;
//				}
				String str = scanner.next();
				for(int k = 0; k < columns; k ++) {  
                    maze[j][k] = str.charAt(j);  
                    if(maze[j][k] == 'S') {  
                        startX = j;  
                        startY = k;
                    } else if(maze[j][k] == 'D') {  
                    	endX = j;
    					endY = k;  
                    } else if(maze[j][k] == 'X') {  
                        blocks ++;  
                    }  
                }
				Arrays.fill(visited[j], false);
			}
			if(columns * rows - blocks < t) {  
                System.out.println("NO"); 
                continue;
            } 
			//dfs超时了，所以我们需要进行剪枝
			if(Math.abs(endX - startX) + Math.abs(endY - startY) > t ||
					(endX + startX + startY + endY + t) % 2 == 1){
	            System.out.println("NO");
	            continue;
	        }
			// bfs(startX, startY);
			dfs(startX, startY, endX, endY, 0);
			if(minMinute == Integer.MAX_VALUE || minMinute != t){
				System.out.println("NO");
			}else{
				System.out.println("YES");
			}
		}
		scanner.close();
	}
	
	
	public void dfs(int x, int y, int endX, int endY, int minute){
		if(maze[x][y] == EXIT && minute == t){
			minMinute = t;
			return;
		}
		//如果最少的步数都不能够在t之前到达
		//还有一个奇偶性剪枝
		
		if (minute > t || t < Math.abs(endX - x) + Math.abs(endY - y) || 
				(t - Math.abs(endX - x) + Math.abs(endY - x)) % 2 != 0){
			return;
		}
		if(minMinute == t){
			return;
		}
		for(int i = 0; i < dir.length; i++){
			int curX = x + dir[i][0];
			int curY = y + dir[i][1];
			if(curX < 0 || curX >= rows || curY < 0 || curY >= columns
					|| maze[curX][curY] == OBSTACLE || visited[curX][curY]){
				continue;
			}
			visited[curX][curY] = true;
			dfs(curX, curY, endX, endY, minute + 1);
			if(minMinute == t){
				return;
			}
			visited[curX][curY] = false;
		}
	}
	
	
	class Node{
		int x, y;
		int time;
		
		public Node() {
		}
		Node(int x, int y) {  
	        this.x = x;  
	        this.y = y;  
	    } 
	}
	
	//这道题目应该不适合用bfs，因为bfs适合用来求最短时间啊之类的
	//但是这道题的要求是正号t秒，多了不行，少了不行
	//比如4 5 5
	//XXS..
	//XX..X
	//X...X
	//X.D.X
	public void bfs(int x, int y){
		Queue<Node> queue = new LinkedList<Node>();
		queue.add(new Node(x, y));
		Node temp;
		while (!queue.isEmpty()){
			temp = queue.poll();
			//这道题要恰好t秒
			if(maze[temp.x][temp.y] == EXIT){
				if(temp.time <= t){
					minMinute = temp.time;
				}else{
					minMinute = temp.time;
					return;
				}
			}
			for (int i = 0; i < dir.length; i++) {
				int nextX = temp.x + dir[i][0];
				int nextY = temp.y + dir[i][1];
				if(nextX < 0 || nextX >= rows || nextY < 0 || nextY >= columns
						|| maze[nextX][nextY] == OBSTACLE || visited[nextX][nextY]){
					continue;
				}
				visited[nextX][nextY] = true;
				Node next = new Node(nextX, nextY);
				next.time = temp.time + 1;
				queue.add(next);
			}
		}
	}
}
